package org.beangle.notification.mail

import java.util.Collections
import java.util.List
import javax.mail.internet.InternetAddress
import org.beangle.commons.lang.Strings
//remove if not needed
import scala.collection.JavaConversions._

object MimeUtils {

  def parseAddress(address: String, encoding: String): collection.mutable.ArrayBuffer[InternetAddress] = {
    if (Strings.isEmpty(address)) new collection.mutable.ArrayBuffer[InternetAddress]
    val parsed = InternetAddress.parse(address)
    val returned = new collection.mutable.ArrayBuffer[InternetAddress]
    for (raw <- parsed) {
      returned.add((if (encoding != null) new InternetAddress(raw.getAddress, raw.getPersonal, encoding) else raw))
    }
    returned
  }
}
